//在html中添加测试脚本节点
//  <script defer="defer" type="text/javascript" src="../test/test.js"></script>

//在body标记中添加属性
//  onload="testMainframe()"

//主方法标记 //@ html文件全名 方法名 如：//@ popLogin.html testPopLogin
//perl脚本或其他语言来读取这些标记并对响应的问题做修改

//@ popLogin.html testPopLogin()
function testPopLogin(){
    /*
    登陆
     */
    var usernameInput = document.getElementsByClassName("-user- tabFocusChange");
    var pwInput = document.getElementsByClassName("-pass- tabFocusChange");
    var buttons = document.getElementsByTagName("button");
    //陈星 E045075  858007
    //杨  E045104  123456
    setTimeout(function(){testMyInput(usernameInput[0], "E045104")}, 500);
    setTimeout(function(){testMyInput(pwInput[0], "123456")}, 1000);
    setTimeout(function(){testMyClick(buttons[0])}, 1500);

}

//@ mainframe.html testMainframe()
function testMainframe(){
    /*
    进入主界面后隐藏广告介绍页面，并点击按钮
     */
    setTimeout(function(){
        var banner_start_image = document.getElementById("banner_start_image");
        banner_start_image.style.visibility = "hidden";
    }, 500);

    setTimeout(function(){
        var myseleStock = document.getElementsByClassName("pageHeader-snav-fItem openNewWtab");
        myseleStock[1].click();
    }, 1000);

}

//@ myStock.html testMyStock(caseId,'testFileName','description')
function testMyStock(caseId, testFileName, description){
    /*
    自选股界面添加股票
     */
    var stockList = ["000100", "nbfd", "shdl"];
    var inputStock = document.getElementsByClassName("form-control");
    var addButton = document.getElementsByClassName("add-to-my-stock btn btn-primary");
    var i = 0;

    testMyStockinner1();

    function testMyStockinner1(){
        var st = stockList[i];
        if (i>=stockList.length){   //这是中断跳出机制
            //测试完成发送测试结果
            //var c = document.getElementById("foo").getElementsByTagName("tr").length;    //自选股列表对象
            testSendResult(testCheckPoint(), caseId, testFileName, description);

            //发送请求标明测试已经完成
            var testCaseControlData = "action=end&id=" + caseId;
            testCrossDomain("TestCaseControl", testCaseControlData);
            return 0;
        }
        setTimeout(function(){testMyInput(inputStock[0], st);}, 1000);
        setTimeout(function(){testMyClick(addButton[0]);}, 2000);
        setTimeout(function(){i++; testMyStockinner1();}, 3000);
    }
}

//测试验证点，组装成json字符串返回
function testCheckPoint(){
    var checkPoints = [
        {
            "pointNo": "1",
            "expectResult": 3,
            "compareMark": "=",
            "testResult": document.getElementById("foo").getElementsByTagName("tr").length,
            "description": "验证点1 id:foo下的tr节点个数为3 为验证通过"
        }
    ];

    for(var cpIntel=0; cpIntel<checkPoints.length; cpIntel++){
        //compareMark  =eq  !=ne, <lt,   >gt,   <=le,   >=ge
        if(checkPoints[cpIntel].compareMark == "="){checkPoints[cpIntel].compareMark = "eq";}
        if(checkPoints[cpIntel].compareMark == "!="){checkPoints[cpIntel].compareMark = "ne";}
        if(checkPoints[cpIntel].compareMark == "<"){checkPoints[cpIntel].compareMark = "lt";}
        if(checkPoints[cpIntel].compareMark == ">"){checkPoints[cpIntel].compareMark = "gt";}
        if(checkPoints[cpIntel].compareMark == "<="){checkPoints[cpIntel].compareMark = "le";}
        if(checkPoints[cpIntel].compareMark == ">="){checkPoints[cpIntel].compareMark = "ge";}
    }

    //var s = JSON.stringify(checkPoints);
    //document.getElementById("show1").value = s;
    return JSON.stringify(checkPoints);
}

function testDebug(){
    //调试方法
    setTimeout(function(){
        var nodeObj = document.getElementById("foo");
        //alert(nodeObj.length);
        testShowNodes(nodeObj);
    }, 2000);
}

